package com.yanfan.zutai.controller;

import com.yanfan.common.core.controller.BaseController;
import com.yanfan.common.core.domain.AjaxResult;
import com.yanfan.common.core.domain.entity.SysUser;
import com.yanfan.common.core.page.TableDataInfo;
import com.yanfan.common.utils.StringUtils;
import com.yanfan.common.utils.poi.ExcelUtil;
import com.yanfan.zutai.domain.BEchartType;
import com.yanfan.zutai.domain.vo.BDeviceZtUserVo;
import com.yanfan.zutai.domain.vo.BHttpRequest;
import com.yanfan.zutai.service.IBEchartTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 图大全Controller
 *
 * @author ruoyi
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/zutai/bEchartType")
public class BEchartTypeController extends BaseController {
    @Autowired
    private IBEchartTypeService bEchartTypeService;

    /**
     * 查询图大全列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BEchartType bEchartType) {
        SysUser user = getLoginUser().getUser();
        if (!user.isAdmin() && user.getUserId()!=1) {
            bEchartType.setUserId(user.getDeptId());
        }
        startPage();
        List<BEchartType> list = bEchartTypeService.selectBEchartTypeList(bEchartType);
        return getDataTable(list);
    }

    /**
     * 导出图大全列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, BEchartType bEchartType) {
        List<BEchartType> list = bEchartTypeService.selectBEchartTypeList(bEchartType);
        ExcelUtil<BEchartType> util = new ExcelUtil<BEchartType>(BEchartType.class);
        util.exportExcel(response, list, "图大全数据");
    }

    /**
     * 获取图大全详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bEchartTypeService.selectBEchartTypeById(id));
    }

    /**
     * 新增图大全
     */
    @PostMapping
    public AjaxResult add(@RequestBody BEchartType bEchartType) {
        return toAjax(bEchartTypeService.insertBEchartType(bEchartType));
    }

    /**
     * 修改图大全
     */
    @PutMapping
    public AjaxResult edit(@RequestBody BEchartType bEchartType) {
        return toAjax(bEchartTypeService.updateBEchartType(bEchartType));
    }

    /**
     * 删除图大全
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bEchartTypeService.deleteBEchartTypeByIds(ids));
    }

    /**
     * 发送请求
     */
    @PostMapping("/sendHttpRequest")
    public AjaxResult sendHttpRequest(@RequestBody BHttpRequest request) {
        return AjaxResult.success("请求成功", bEchartTypeService.sendHttpRequest(request));
    }

    @ApiOperation("分配图表")
    @PostMapping("/assignment")
    public AjaxResult assignment(@RequestBody BEchartType bEchartType) {
        if (null == bEchartType.getDeptId()) {
            return error("请选择分配机构");
        }
        if (StringUtils.isEmpty(bEchartType.getZutaiId())) {
            return error("请选择图表");
        }
        return bEchartTypeService.fpEchartUser(bEchartType.getDeptId(), bEchartType.getZutaiId());
    }
}
